import datetime

import xlsxwriter

workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet('sheet1')
# 法一
worksheet.write('A1', 'write something')
# 法二
worksheet.write(1, 0, 'Hello World')

 # 写⼊数字
worksheet.write(0, 1, 32)
worksheet.write(1, 1, 32.3)
# 写⼊函数
worksheet.write(2, 1, '=sum(B1:B2)')
# 插⼊图⽚
worksheet.insert_image(0, 5, 'aa.png')
worksheet.insert_image(0, 5, 'aa.png', {'url': 'http://httpbin.org/'})
# 写⼊⽇期
d = workbook.add_format({'num_format': 'yyyy-mm-dd'})
worksheet.write(0, 2, datetime.datetime.strptime('2017-09-13', '%Y-%m-%d'), d)
# 设置行高与列宽
worksheet.set_row(0, 40)
worksheet.set_column('A:B', 20)
# 设置样式
# 自定义格式
# f = workbook.add_format({'border': 1,'font_size': 20,'bold': True,'align':'center','bg_color': 'yellow'})
# worksheet.write('A5', 'hello', f)
# worksheet.set_row(0, 40, f)
# worksheet.set_column('A:B', 20, f)

worksheet = workbook.add_worksheet('sheet2')
worksheet.write_column('A1',[1,2,3,4,5])
worksheet.write_row('A6',[6,7,8,9])
# 合并单元格
worksheet = workbook.add_worksheet('sheet3')
worksheet.merge_range(7, 5, 11, 8, 'hello world')

workbook.close()


